package odometerDevice.connectionDevice.android.bluetooth;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.microedition.io.StreamConnection;

public class ProcessConnectionThread implements Runnable{

	private StreamConnection mConnection;
	
	// Constant that indicate command from devices
	private static final int EXIT_CMD = -1;
	private static final int KEY_RIGHT = 1;
	private static final int KEY_LEFT = 2;
	private InputStream inputStream;
	private OutputStream outputSream;
	
	public ProcessConnectionThread(StreamConnection connection) throws IOException
	{
		mConnection = connection;
		inputStream = mConnection.openInputStream();
	}
	
	@Override
	public void run() {
//		try {
//			
//			// prepare to receive data
//			
//	        
//			System.out.println("waiting for input");
//	        
//	        while (true) {
//	        	int command = inputStream.read();
//	        	
//	        	if (command == EXIT_CMD)
//	        	{	
//	        		System.out.println("finish process");
//	        		break;
//	        	}
//	        	
//	        	//processCommand(command);
//        	}
//        } catch (Exception e) {
//    		e.printStackTrace();
//    	}
	}
	
	
	public byte[] read(){
		try {
			byte[]values= new byte[3];
			System.out.println("Received " + inputStream.read(values));
			return values;
		} catch (IOException ioe) {
			System.out.println("IO Exception reading bytes:");
			System.out.println(ioe.getMessage());
		}
		return null;
	}
	
	public void write(byte[] rgbValues){
		try {
			System.out.println("Sending " + rgbValues);
			outputSream.write(rgbValues);
			outputSream.flush();

		} catch (IOException ioe) {
			System.out.println("IO Exception writing bytes:");
			System.out.println(ioe.getMessage());
		}
	}
	
}
